from utils.mysqlutil import MysqlUtil

mysql = MysqlUtil()

class RdTestcase:

    # 根据表查找出所有的数据
    def load_all_case(table):
        # 查找出所有的表信息
        sql = f"select * from " + table
        results = mysql.get_fetchall(sql)
        return results

    # 得到一条osd数据
    def find_osd_id(id):
        sql = f"select * from osd where id =" + str(id)
        results = mysql.get_fetchone(sql)
        return results

    # 根据开始和结束位置确定查询的数据条数
    def find_osd_limit(start, count):
        sql = f"select * from compositions limit " + str(start) + "," + str(count)
        results = mysql.get_fetchall(sql)
        return results

    # 得到一条告警数据
    def find_gaojing_id(id):
        sql = "select * from gaojing where id =" + str(id)
        results = mysql.get_fetchone(sql)
        return results


    # 根据开始和结束位置确定查询的数据条数
    def find_gaojing_limit(start, count):
        sql = f"select * from gaojing limit " + str(start) + "," + str(count)
        results = mysql.get_fetchall(sql)
        return results

    # 向移动数据库中写入移动侦测或者区域入侵布放时间段 
    def add_defencetime(weekDay, timeDuration1, timeDuration2, timeDuration3, timeDuration4, timeDuration5):
        sql = " insert into defencetime(weekDay, timeDuration1, timeDuration2, timeDuration3, timeDuration4, timeDuration5) VALUES " +\
              "("+str(weekDay)+str(timeDuration1)+str(timeDuration2)+str(timeDuration3)+str(timeDuration4)+str(timeDuration5) +")"
        mysql.sql_execute(sql)

    # 得到一条移动侦测数据
    def find_yidong_id(id):
        sql = f"select * from yidongzhence where id =" + str(id)
        results = mysql.get_fetchone(sql)
        return results